<?php include ('layout/header.php'); ?>
<?php
    if(isset($_POST['submit'])){
        $user = Utils::getValPost('username');
        $pass = Utils::getValPost('password');
        if(Utils::isStringValid($user) && Utils::isStringValid($pass)){
            $userTbl = new DALUserAccount();
            $acc = $userTbl->loginUser($user, $pass);
            if(!$acc){
                Utils::redirect('index.php', array('message' => 'Account not found!'));                
            }else{
                $_SESSION['id'] = $acc->id;
                $_SESSION['username'] = $acc->username;
                $_SESSION['balance'] = $acc->balance;
                Utils::redirect('main.php');
            }
        }
    }
?>


        <form class="form-signin" role="form" method="POST" action="index.php">
            <h2 class="form-signin-heading">Please sign in</h2>
            <input type="text" class="form-control" name="username" placeholder="Username" required="" autofocus="">
            <input type="password" class="form-control" name="password" placeholder="Password" required="">
            <button class="btn btn-lg btn-primary btn-block" type="submit" name="submit" value="submit">Sign in</button>
      </form>

<?php include ('layout/footer.php'); ?>    